package com.coocaa.circleprogress;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

/**
 * @ Created on: 2020/5/11
 * @Author: LEGION XiaoLuo
 * @ Description:
 */
public class LineView extends View {
    private Paint mLinePaint;
    public LineView(Context context) {
        super(context);
        init();
    }

    public LineView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public LineView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public LineView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
    }

    private void init() {
        mLinePaint = new Paint();
        mLinePaint.setColor(Color.BLACK);
        mLinePaint.setStrokeWidth(4);
        mLinePaint.setAntiAlias(true);
    }

    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);
        canvas.drawPoint(80,140, mLinePaint);

        //90_60
        double angle = Math.toRadians(60);
        double x = 100 * Math.cos(angle);
        double y = 100 * Math.sin(angle);
        canvas.drawLine(80, 140, 80 + (float)x, 140 + (float)y, mLinePaint);

        //-90_-60
        double negativeAngle = Math.toRadians(-60);
        double x2  = 100*Math.cos(negativeAngle);
        double y2 = 100*Math.sin(negativeAngle);
        canvas.drawLine(80, 140, 80 + (float)x2, 140 + (float)y2, mLinePaint);
    }
}
